package com.zjq.authoritysystem.entity;

import java.util.Collection;
import java.util.Date;
import java.io.Serializable;
import java.util.List;

import com.baomidou.mybatisplus.annotation.*;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnore;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.springframework.boot.autoconfigure.security.servlet.UserDetailsServiceAutoConfiguration;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

/**
 * <p>
 *
 * </p>
 *
 * @author BetOnMe
 * @since 2023-09-18
 */
@Data
@TableName("users")
@EqualsAndHashCode(callSuper = false)
@ApiModel(value = "Users对象", description = "")
public class User implements Serializable, UserDetails {

    private static final long serialVersionUID = 1L;

    @TableId(value = "id", type = IdType.AUTO)
    private Integer id;

    @ApiModelProperty(value = "账户")
    private String username;

    @ApiModelProperty(value = "密码")
    private String password;

    @ApiModelProperty(value = "账号是否过期")
    private boolean isAccountNonExpired = true;

    @ApiModelProperty(value = "账号是否被锁定")
    private boolean isAccountNonLocked = true;

    @ApiModelProperty(value = "密码是否过期")
    private boolean isCredentialsNonExpired = true;

    @ApiModelProperty(value = "账户是否可用")
    private boolean isEnabled = true;

    @ApiModelProperty(value = "真实姓名")
    private String realName;

    @ApiModelProperty(value = "昵称")
    private String nickName;

    @ApiModelProperty(value = "所属部门编号")
    private Integer departmentId;

    @ApiModelProperty(value = "所属部门名称")
    private String departmentName;

    @ApiModelProperty(value = "性别(0:女，1:男)")
    private Integer gender;

    @ApiModelProperty(value = "电话")
    private String phone;

    @ApiModelProperty(value = "邮件")
    private String email;

    @ApiModelProperty(value = "头像")
    private String avatar;

    /**
     * 是管理员
     */
    public final static Integer IS_ADMIN_YES = 1;

    /**
     * 不是管理员
     */
    public final static Integer IS_ADMIN_NO = 0;

    @ApiModelProperty(value = "是否是管理员(0:否,1：是)")
    private Integer isAdmin;

    @TableField(fill = FieldFill.INSERT)
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    @ApiModelProperty(value = "创建时间")
    private Date createTime;

    @TableField(fill = FieldFill.INSERT_UPDATE)
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    @ApiModelProperty(value = "修改时间")
    private Date updateTime;

    /**
     * 未删除
     */
    public final static Integer IS_DELETE_NO = 0;

    /**
     * 已删除
     */
    public final static Integer IS_DELETE_YES = 1;

    @ApiModelProperty(value = "是否删除（0：未删除，1：已删除）")
    private Integer isDelete;

    /**
     * 权限列表
     */
    @TableField(exist = false)
    Collection<? extends GrantedAuthority> authorities;

    /**
     * 查询的用户权限列表
     */
    @TableField(exist = false)
    List<Permission> permissionList;

    /**
     * 角色
     */
    @TableField(exist = false)
    private String roleName;

    /**
     * 转JSON时过滤掉password
     * @return
     */
//    @JsonIgnore
//    public String getPassword() {
//        return password;
//    }
}
